add a new functions - Remove#172
add a new functions - Remove#172Luoxin wants to merge 6 commits intoelliotchance:masterfrom Luoxin:master
Conversation
| {"Unique", "unique.go", ForNumbersAndStrings, "n"}, | ||
| {"Unshift", "unshift.go", ForAll, "n"}, | ||
| {"Values", "values.go", ForMaps, "n"}, | ||
| {"Remove", "remove.go", ForNumbersAndStrings, "n⋅n"}, |
There was a problem hiding this comment.
Please keep these lines sorted by name.
Also, O(n^2) isn't quite correct, it would be O(kn) but more on that below.
| @@ -0,0 +1,19 @@ | |||
| package functions | |||
|
|
|||
| // Remove items from slice when item existed | |||
There was a problem hiding this comment.
// Remove returns a new slice that does not include any of the items.|
@Luoxin thanks for creating this diff, with a few tweaks I'm happy to merge. You will also need to update the README. |
- change n^2 to 2n
|
Thank you for the correction, I made some changes |
| | [`Unique`](#unique) | ✓ | ✓ | | | n | Unique returns a new slice with all of the unique values. | | ||
| | [`Unshift`](#unshift) | ✓ | ✓ | ✓ | | n | Unshift adds one or more elements to the beginning of the slice and returns the new slice. | | ||
| | [`Values`](#values) | | | | ✓ | n | Values returns the values in the map. | | ||
| | [`SortUsing`](#sortusing) | ✓ | | ✓ | | n⋅log(n) | SortUsing works similar to sort.Slice. However, |
There was a problem hiding this comment.
The format of the table has been mangled. Please fix.
|
|
||
| Due to Go's randomization of iterating maps the order is not deterministic. | ||
|
|
||
| ## Remove |
| {"Unshift", "unshift.go", ForAll, "n"}, | ||
| {"Values", "values.go", ForMaps, "n"}, | ||
| {"Remove", "remove.go", ForNumbersAndStrings, "n⋅n"}, | ||
| {"Remove", "remove.go", ForNumbersAndStrings, "2n"}, |
There was a problem hiding this comment.
O(2n) is not a valid complexity, the constant would be removed to O(n). Also, you must keep the functions sorted.
| the slice and returns the new slice. | | [`Values`](#values) | | | | ✓ | n | Values returns the | ||
| values in the map. | | [`Remove`](#values) | ✓ | ✓ | | ✓ | 2n | Remove returns a new slice that does | ||
| not include any of the items. | | ||
| | [`SortUsing`](#sortusing) | ✓ | | ✓ | | n⋅log(n) | SortUsing works similar to sort.Slice. However, unlike sort.Slice the slice returned will be reallocated as to not modify the input slice. | |
There was a problem hiding this comment.
This is still mangled, you can repair this by restoring the original file:
git checkout origin/master -- README.mdNow add the Remove line back in and commit again.
| | [`Product`](#product) | | ✓ | | | n | Product is the product of all of the elements. | | ||
| | [`Random`](#random) | ✓ | ✓ | ✓ | | 1 | Random returns a random element by your rand.Source, or zero | | ||
| | [`Reduce`](#reduce) | ✓ | ✓ | | | n | Reduce continually applies the provided function over the slice. Reducing the elements to a single value. | | ||
| | [`Remove`](#remove) | ✓ | ✓ | | ✓ | n | Remove returns a new slice that does not include any of the items. | |
There was a problem hiding this comment.
Maps should not be ticked.
Did you format this file after running generate.go?
|
@Luoxin - if you want to revisit this, you can build against v2 which is much more flexible. |
|
I will do something in this weekend |
#171
This change is